﻿Imports System.Text
Namespace Models
    Public Class clsZModuleScriptRow
        Inherits ADODBU.RowClass
        Private mVar_Mod_Id As System.String
        Private mVar_Urut As System.Int32
        Private mVar_Script As System.String
        Private mVar_DirtyMod_Id As Boolean = False
        Private mVar_DirtyUrut As Boolean = False
        Private mVar_DirtyScript As Boolean = False
        Private mIsOnInit As Boolean
        Public DataSource As ADODBU.Recordset
        Public RowOrigin As clsZModuleScriptRow
        ''[------------------------------------------------------------------------]'
        Public Sub New()
            RowOrigin = New clsZModuleScriptRow(True)
        End Sub
        ''[------------------------------------------------------------------------]'
        Friend Sub New(ByVal lCut As Boolean)
            '--- untuk memutus loop reference 
        End Sub
        ''[------------------------------------------------------------------------]'
        ''' <summary>
        ''' create new this class from inherited of this class or its self
        ''' </summary>
        ''' <param name="recdataRow"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal recdataRow As ADODBU.RowClass)
            RowOrigin = New clsZModuleScriptRow(True)
            Me.JoinValue(recdataRow)
        End Sub
        ''[------------------------------------------------------------------------]'
        Public Sub New(ByVal recData As ADODBU.Recordset)
            RowOrigin = New clsZModuleScriptRow(True)
            DataSource = recData
            Try
                InitVar(recData.GetCurrentDataRow)
            Catch
            End Try
        End Sub

        ''[------------------------------------------------------------------------]'
        Public Sub New(ByVal recdataRow As DataRow)
            RowOrigin = New clsZModuleScriptRow(True)
            InitVar(recdataRow)
        End Sub

#Region "Initialize vars "
        ''[------------------------------------------------------------------------]'
        Private Sub InitVar(ByVal Fields As DataRow)
            Try
                mVar_Mod_Id = Fields("Mod_Id")
                RowOrigin.Mod_Id = mVar_Mod_Id
            Catch e As Exception
            End Try
            Try
                mVar_Urut = Fields("Urut")
                RowOrigin.Urut = mVar_Urut
            Catch e As Exception
            End Try
            Try
                mVar_Script = Fields("Script")
                RowOrigin.Script = mVar_Script
            Catch e As Exception
            End Try
        End Sub


#End Region
        ''[------------------------------------------------------------------------]'
#Region "Properties"
        Public Property Mod_Id() As System.String
            Get
                Return mVar_Mod_Id
            End Get
            Set(ByVal Value As System.String)
                mVar_Mod_Id = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("Mod_Id"))
                If Not mIsOnInit Then
                    mVar_DirtyMod_Id = True
                End If
            End Set
        End Property
        Public Property Urut() As System.Int32
            Get
                Return mVar_Urut
            End Get
            Set(ByVal Value As System.Int32)
                mVar_Urut = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("Urut"))
                If Not mIsOnInit Then
                    mVar_DirtyUrut = True
                End If
            End Set
        End Property
        Public Property Script() As System.String
            Get
                Return mVar_Script
            End Get
            Set(ByVal Value As System.String)
                mVar_Script = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("Script"))
                If Not mIsOnInit Then
                    mVar_DirtyScript = True
                End If
            End Set
        End Property
        Public ReadOnly Property Mod_IdIsDirty() As Boolean
            Get
                Return mVar_DirtyMod_Id
            End Get
        End Property
        Public ReadOnly Property UrutIsDirty() As Boolean
            Get
                Return mVar_DirtyUrut
            End Get
        End Property
        Public ReadOnly Property ScriptIsDirty() As Boolean
            Get
                Return mVar_DirtyScript
            End Get
        End Property
#End Region
        ''[------------------------------------------------------------------------]'
        Public Function SaveToDataSource() As String
            Dim msgErr As String
            msgErr = ""
            If mVar_DirtyMod_Id Then
                Try
                    DataSource.Fields("Mod_Id") = mVar_Mod_Id
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtyUrut Then
                Try
                    DataSource.Fields("Urut") = mVar_Urut
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtyScript Then
                Try
                    DataSource.Fields("Script") = mVar_Script
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            Return msgErr
        End Function

        ''[------------------------------------------------------------------------]'
        Public Sub ClearDirty()
            mVar_DirtyMod_Id = False
            mVar_DirtyUrut = False
            mVar_DirtyScript = False
        End Sub
        ''[------------------------------------------------------------------------]'
        Public Sub SetDirty()
            mVar_DirtyMod_Id = True
            mVar_DirtyUrut = True
            mVar_DirtyScript = True
        End Sub

    End Class
End Namespace